import time

from selenium.webdriver.common.by import By
from common.common import driver

# 帖子互动测试
class TestInteractions:
    url=""
    driver=""

    def __init__(self):
        self.driver=driver.driver
        self.url="http://127.0.0.1:58080/index.html#"
        self.driver.get(self.url)

    # 点赞测试
    def Thumbs_up(self):
        # 点赞别人帖子，是否成功
        # 点击别人帖子
        self.driver.find_element(By.CSS_SELECTOR, "#artical-items-body > div:nth-child(2) > div > div.col > div.text-truncate > a").click()
        # 点击点赞按键
        self.driver.find_element(By.CSS_SELECTOR, "#details_btn_like_count").click()
        # 若提示成功则点赞成功
        time.sleep(0.5)
        self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div > h2")
        # 添加屏幕截图
        driver.getScreeShot()
        # 返回主页
        self.driver.find_element(By.CSS_SELECTOR, "#nav_board_index > a").click()

        # 点赞自己帖子，是否成功
        self.driver.find_element(By.CSS_SELECTOR, "#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a").click()
        time.sleep(0.5)
        self.driver.find_element(By.CSS_SELECTOR, "#details_btn_like_count").click()
        time.sleep(0.5)
        self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div > h2")
        # 添加屏幕截图
        driver.getScreeShot()
        self.driver.find_element(By.CSS_SELECTOR, "#nav_board_index > a").click()

    # 评论测试
    def comments(self):
        # 评论自己帖子，是否成功
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a").click()
        time.sleep(0.5)
        # 滚动到页面最底部
        driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
        time.sleep(3)
        self.driver.find_element(By.CSS_SELECTOR, "#article_details_reply > div.editormd-toolbar > div > ul > li:nth-child(4) > a > i").click()
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, "#details_btn_article_reply").click()
        # 提示回复成功
        time.sleep(0.5)
        text = self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div > h2").text
        assert text=="提示"
        # 添加屏幕截图
        driver.getScreeShot()
        driver.execute_script("window.scrollTo(0, 0);")
        time.sleep(3)
        self.driver.find_element(By.CSS_SELECTOR, "#nav_board_index > a").click()

        # 评论别人帖子，是否成功
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(2) > div > div.col > div.text-truncate > a").click()
        time.sleep(0.5)
        # 滚动到页面最底部
        driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
        time.sleep(3)
        self.driver.find_element(By.CSS_SELECTOR, "#article_details_reply > div.editormd-toolbar > div > ul > li:nth-child(4) > a > i").click()
        self.driver.find_element(By.CSS_SELECTOR, "#details_btn_article_reply").click()
        time.sleep(0.5)
        text = self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div > h2").text
        assert text == "提示"
        # 添加屏幕截图
        driver.getScreeShot()
        driver.execute_script("window.scrollTo(0, 0);")
        time.sleep(3)
        self.driver.find_element(By.CSS_SELECTOR, "#nav_board_index > a").click()

